#!/usr/bin/perl -w

use strict;
use warnings;
use Data::Dumper;
use RFCMail::PackIt;

$Data::Dumper::Terse = 1;
$Data::Dumper::Indent = 0;

print "Enter things to be converted as test(type, data);\n";
while (<>) {
    eval;
}

sub test {
    my $acc = RFCMail::PackIt::Access->new();
    my ($type, $data) = @_;
    print "Encoding...\n";
    eval {
	$acc->write_type($type, $data);
    };
    if ($@) {
	print "Failed: $@";
    }
    else {
	print "As bytes:";
	for (unpack("C*", $acc->data)) {
	    printf(' %02x', $_);
	}
	print "\nDecoding...\n";
	$acc = RFCMail::PackIt::Access->new($acc->data);
	$data = eval { $acc->read_type($type) };
	if ($@) {
	    print "Failed: $@";
	}
	else {
	    print Dumper($data), "\n";
	}
    }
}
